package com.dz.xjd.ui.presenter;

import com.dz.xjd.app.App;
import com.dz.xjd.base.baserx.RxSubscriber;
import com.dz.xjd.ui.contract.RegisterContract;
import com.dz.xjd.utils.EncryptDecrypt;
import com.dz.xjd.utils.KeyUtil;
import com.dz.xjd.utils.ToastUtil;
import com.orhanobut.logger.Logger;

public class RegisterPresenter extends RegisterContract.Presenter{


    @Override
    public void getRegisterRequest(String header, String params) {
        mModel.getRegisterData(header, params) .subscribe(new RxSubscriber<String>(mContext,true){
            @Override
            protected void _onNext(String data) {
                String[] keys = KeyUtil.getKey(App.getToken());
                try {
                    String str = EncryptDecrypt.decrypt(keys[0],data,keys[1]);
                    Logger.d("getRegisterRequest---"+str);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                ToastUtil.showShort("注册成功");

                mView.returnRegisterData();
            }

            @Override
            protected void _onError(String message) {
                ToastUtil.showShort(message);
            }
        });
    }

    @Override
    public void sendValidateRequest(String header, String params) {
        Logger.d("header--"+header);
        Logger.d("params--"+params);
        mModel.sendValidate(header, params).subscribe(new RxSubscriber<String>(mContext,true){
            @Override
            protected void _onNext(String data) {
                String[] keys = KeyUtil.getKey(App.getToken());
                try {
                    String str = EncryptDecrypt.decrypt(keys[0],data,keys[1]);
                    Logger.d("getRegisterRequest---"+str);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                ToastUtil.showShort("验证码发送成功");
            }

            @Override
            protected void _onError(String message) {
                ToastUtil.showShort(message);
            }
        });
    }
}
